<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            box-sizing: border-box;
        }

        #app {
            margin: 0 auto;
            width: 80%;
            border: black 1px solid;
            height: 100vh;
        }
    </style>
</head>

<body>
    <div id="app"></div>
</body>
<script>
    //5、使用原型+构造函数创建对象
    function Person(id, name, age) {
        this.id = id
        this.name = name
        this.age = age
    }
    //使用构造函数Person找原型对象
    let proto = Person.prototype
    //给原型对象添加一个属性hobby
    proto.hobby = ['lol', "qq飞车"]
    console.log(proto)
    //给原型添加一个函数返回当前对象的属性
    proto.info = function () {
        return this.id + "," + this.name + "," + this.age
    }

    //创建实例对象
    let p = new Person(1, "tom", 20)
    let p1 = new Person(2, "tom1", 20)
    let p2 = new Person(3, "tom2", 20)
    console.log(p.info())

    //使用对象找到原型对象
    let proto1 = p.__proto__
    proto1.hobby = ['lol', "qq飞车", '王者']
    let proto2 = p.__proto__
    proto2.hobby = ['lol', "...", '王者']
    console.log(p1.info())

    //给String的原型对象添加方法，作用是去除首尾空格
    String.prototype.trims = function () {
        return this.trim()
    }
    console.log("  hello_proto ".trims())

    //给date添加一个格式化方法
    Date.prototype.formateDate = function () {
        let year = this.getFullYear()
        //...
        return '这是格式好的日期'
    }
    let date = new Date()
    let str = date.formateDate()
    console.log(str)
    let date1 = new Date()
    console.log(date1.getFullYear())
</script>

</html>